import 'package:flutter/material.dart';

class BottomNavigationDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'BottomNavigationDemo', home: MyHomePage());
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage> {
  int currentPos = 1;
  final _widgetOptions = [
    Text('Index:0 信息'),
    Text('Index:1 通讯录'),
    Text('Index:2 发现')
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('BottomNavigationDemo'),
      ),
      body: Center(
        child: _widgetOptions.elementAt(currentPos),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.chat), title: Text('信息')),
          BottomNavigationBarItem(
              icon: Icon(Icons.contacts), title: Text('通讯录')),
          BottomNavigationBarItem(
              icon: Icon(Icons.account_circle), title: Text('发现'))
        ],
        currentIndex: currentPos,
        fixedColor: Colors.blueAccent,
        onTap: _onItemTap,
      ),
    );
  }

  void _onItemTap(int index) {
    setState(() {
      currentPos = index;
    });
  }
}
